<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/res/back/css/base.css" rel="stylesheet" type="text/css" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css"
	rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/bootstrap3/bootstrap.autocomplete.js"
	type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js"
	type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js"
	type="text/javascript"></script>
<script src="/res/third/easyUI/jquery.easyui.min.js"
	type="text/javascript"></script>
<script src="/res/third/easyUI/locale/easyui-lang-zh_CN.js"
	type="text/javascript"></script>
<script type="text/javascript"
	src="/res/third/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/res/third/ueditor/ueditor.all.js"></script>
<script type="text/javascript"
	src="/res/third/ueditor/lang/zh-cn/zh-cn.js"></script>


<script type="text/javascript">
	
</script>

<style type="text/css">
.showAsset {
	display: inline-block;
	float: left;
	width: 250px;
	height: 270px;
	margin-right: 34px;
	position: relative;
	margin-left: 11px;
	margin-top: 11px;
	padding: 15px;
	border: 1px solid #f2f2f2;
}
</style>

</head>

<body>
	<div class="panel panel-info panel-content" style="overflow-y:scroll">
		<div class="panel-heading" style="margin-bottom: 15px">
			<label for="companyname" class="center-block" style="text-align: left">基本信息</label>
		</div>
		<form action="" method="post" class="form-horizontal" role="form">
			<div class="form-group">
				<label class="col-sm-2 control-label" id="clickforpro">公司名称：</label>
				<div class="col-sm-2">
					<input type="text" class="form-control" min="1" required="required" name="companyName" id="companyName" autocomplete="off">
				</div>
			</div>
		</form>

		<div class="panel-heading" style="margin-bottom: 15px">
			<label for="companyname" class="center-block" style="text-align: left">签约信息</label>
		</div>
		<form action="companysign_o_add.do" method="post"
			class="form-horizontal" role="form" id="signForm">
			<input type="hidden" name="companyId" id="companyId">
			<div class="form-group">
				<label class="col-sm-2 control-label " id="clickforpro">合作身份：</label>
				<div class="col-sm-2">
					<select class="form-control" name=identity>
						<option value="">请选择身份类型</option>
						[#list identityMap?keys as key]
						<option value="${key}">${identityMap[key]!}</option>
						[/#list]
					</select>
				</div>
				<label class="col-sm-2 control-label " id="clickforpro">签约金额：</label>
				<div class="col-sm-2">
					<input type="number" class="form-control" min="1" required="required" name="promiseAmount">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label ">签约时间：</label>
				<div class="col-sm-2">
					<input type="text" style="width: 270px; height: 34px" min="1" name="signDate" id="startdate">
				</div>
			</div>
			<div class="form-group">
                <label class="col-sm-2 control-label ">结束时间：</label>
                <div class="col-sm-2">
                    <input type="text" style="width: 270px; height: 34px" min="1" name="endDate" id="enddate">
                </div>
			</div>
			<div class="form-group" style="margin-bottom:5px">
				<label class="col-sm-2 control-label ">签约合同：</label>
				<div class="col-sm-2">
					<input type="text" class="form-control" min="1" required="required" name="contractFile" id="contractFile">
				</div>
				<button onclick="uploaddialog()" type="button" class="btn btn-info">添加合同</button>
			</div>
			<div class="form-group" style="text-align: center;">
                <input id="sub" type="button" class="btn btn-info" value="提交" />
			</div>
			<img id="contract" src="" style="margin-left:250px;margin-bottom:20px"/>
		</form>
		<div class="panel-heading" style="margin-bottom: 15px">
			<label for="companyname" class="center-block" style="text-align: left">资质信息</label>
		</div>
		<div id="Assets" style="height: 100%"></div>
	</div>
</body>
</html>
<script type="text/javascript">
	$(function() {
		$("#startdate").datebox({
			formatter : function(date) {
				var y = date.getFullYear();
				var m = date.getMonth() + 1;
				var d = date.getDate();
				return y + '-' + m + '-' + d;
			},
			onSelect : function(dateselect) {
				//enddate清空
				$('#enddate').datebox('setValue', '');
				$("#enddate").datebox("calendar").calendar({
					validator : function(date) {
						return dateselect < date;
					}
				});
			}
		})

		$("#enddate").datebox({
			formatter : function(date) {
				var y = date.getFullYear();
				var m = date.getMonth() + 1;
				var d = date.getDate();
				return y + '-' + m + '-' + d;
			}
		})
		$(".datebox").css("border-radius", "4px");
		$(".combo-text").css("padding", "12px");

		//公司名称自动补全
		$('#companyName').autocomplete({
			source : function(query, process) {
				var matchCount = 6; //this.options.items;返回结果集最大数量
				$.post("/company/autocustomer.do", {
					"query" : query,
					"matchCount" : matchCount
				}, function(respData) {
					var json = JSON.parse(respData);
					return process(json.obj);
				});
			},
			formatItem : function(items) {
				return items["companyName"];
			},
			setValue : function(items) {
				return {
					'data-value' : items["companyName"],
					'real-value' : items["id"]
				};
			},
			updater : function(item) {
				var realvalue = this.$menu.find('.active').attr('real-value');
				getFiles(realvalue);
				return item
			}
		});
	})

	function getFiles(companyId) {
		$.ajax({
			url : '/company/checkCompanySign.do',
			type : 'post',
			dataType : 'json',
			data : {
				id : companyId
			},
			beforeSend : function() {
				art.dialog.tips("获取公司资质中...");
			},
			success : function(data) {
				if(data && data.success) {
                    var htmlText = ""
                    for (var i in data.obj) {
                        htmlText += "<div class='showAsset'>";
                        htmlText += "<span style='width: 100%;height: 20px;display: inline-block;text-align: center;font-size: 12px;font-weight: bold;color: #8C7AB7;'>"
                                + data.obj[i].name + "</span>";
                        htmlText += "<span style='display: inline-block;width: 100%;height:220px;text-align: center;'><img style='max-width: 100%;max-height: 100%;' src='"
                                + data.obj[i].attachfile + "'></span>";
                        htmlText += "</div>"
                    }
                    $("#Assets").append(htmlText);
                } else if(data.msg) {
					alert(data.msg);
					$('#companyName').val('');
				} else {
					alert('操作失败');
				}
			}
		});
	}
	$('#sub').click(function() {
		var companyName = $("input[name='companyName']").val();
		if (!companyName) {
			alert('请选择一个公司!');
			return;
		}
		var identity = $("select[name='identity']").val();
		if (!identity) {
			alert('请选择身份类型!');
			return;
		}
		var promiseAmount = $("input[name='promiseAmount']").val();
		if (!promiseAmount) {
			alert('请输入签约金额!');
			return;
		}
		var signDate = $("input[name='signDate']").val();
		if (!signDate) {
			alert('请选择签约日期!');
			return;
		}
		var endDate = $("input[name='endDate']").val();
		if (!endDate) {
			alert('请选择结束日期!');
			return;
		}
		var contractFile = $("input[name='contractFile']").val();
		if (!contractFile) {
			alert('请上传签约合同!');
			return;
		}
		var companyId = $("#companyName").attr('real-value');
		$("#companyId").val(companyId);
		$("#signForm").submit();
	});

	function uploaddialog() {
		//var param ={id:newproid};
		exceldialog = art.dialog.uploadFile("上传合同", {
			callback : "uploadcallback",
			userpath : "admin"
		});
	}

	function uploadcallback(response) {
		//alert(response.url);
		//alert(params.id);
		exceldialog.close();
		$("#contract").attr("src", response.url);
		$("#contractFile").val(response.url)

	}
</script>
